package com.example.flowerpcback.controller;

import com.example.flowerpcback.dto.Menus;
import com.example.flowerpcback.dto.User;
import com.example.flowerpcback.req.MenusReq;
import com.example.flowerpcback.req.UserReq;
import com.example.flowerpcback.resp.CommonResp;
import com.example.flowerpcback.resp.MenusResp;
import com.example.flowerpcback.resp.PageResp;
import com.example.flowerpcback.resp.UserResp;
import com.example.flowerpcback.services.MenusService;
import com.example.flowerpcback.services.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController //这是返回接口
@RequestMapping("/menus")
public class MenusController {

    private static final Logger LOG = LoggerFactory.getLogger(MenusController.class);

    @Resource
    private MenusService menusService;

    @GetMapping("/all")
    public CommonResp<List<MenusResp>> all(@Valid MenusReq req){
        CommonResp<List<MenusResp>> resp= new CommonResp<>();
        List<MenusResp> res = menusService.all(req);
        resp.setData(res);
        return  resp;
    }

    @PostMapping("/save")
    public CommonResp<MenusResp> save(@Valid @RequestBody MenusReq req){
        CommonResp<MenusResp> resp= new CommonResp<>();
        MenusResp menusResp = menusService.save(req);
        resp.setData(menusResp);
        return resp;
    }

    @PostMapping("/batchUpdate")
    public CommonResp<List<Menus>> batchUpdate(@Valid @RequestBody List<MenusReq> req){
        CommonResp<List<Menus>> resp= new CommonResp<>();
        List<Menus> menusResp = menusService.batchUpdate(req);
        resp.setData(menusResp);
        return resp;
    }

    @GetMapping("/delete")
    public CommonResp delete(@Valid MenusReq req){
        CommonResp resp= new CommonResp<>();
        menusService.delete(req);
        return  resp;
    }
}

